package com.hspedu.jdbc.homework.homework01;

import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/4/8
 * @time 11:12
 */
public class Homework01 {
    public static void main(String[] args) throws IOException, ClassNotFoundException, SQLException {

        Properties properties = new Properties();
        properties.load(new FileInputStream("D:\\workspace_idea\\java0\\hspedu\\chapter25\\src\\mysql2.properties"));
        String user = properties.getProperty("user");
        String password = properties.getProperty("password");
        String driver = properties.getProperty("driver");
        String url = properties.getProperty("url");

        Class<?> cls = Class.forName(driver);
        Connection connection = DriverManager.getConnection(url, user, password);

        Statement statement = connection.createStatement();
//        int affectRows = statement.executeUpdate("insert into `news` values(null,'上海新闻')," +
//                "(null,'北京新闻'),(null,'南京新闻'),(null,'新疆新闻'),(null,'河南新闻')");
//        int affectRows = statement.executeUpdate("update `news` set content='纽约新闻' where id = 1 ");
        int affectRows = statement.executeUpdate("delete from `news` where id = 3");
        System.out.println("受影响的行数是："+affectRows);
        if (connection != null) {
            connection.close();
        }
    }
}
